{include file='common/head'}
<!--员工发布&#45;&#45;说天喊地-->
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">
    <blockquote class="layui-elem-quote layui-text">
        <div class="demoTable layui-form">
            <!--<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>-->
            <div class="demoTable layui-form">
                <div class="layui-input-inline">
                    <input type="text" placeholder="请输入用户名称" name="user_name" lay-verify="required"  autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <input type="text" placeholder="请输入课程名称" name="name" lay-verify="required"  autocomplete="off" class="layui-input">
                </div>
                <button class="layui-btn " data-type="reload" ><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
        </div>
    </blockquote>
    <div class="demoTable layui-for">
        <table class="layui-table" lay-data="{height: 'full-150', url:'{:url('Book/getUserBookList')}',edit:true, page:true, id:'testReload',loading:true}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80,fixed: true,templet:'#id'}">编号</th>
                <th lay-data="{field:'user_name', width:120,templet: '#user_name'}">用户名</th>
                <th lay-data="{field:'name',width:200}">课程名称</th>
                <th lay-data="{field:'status',width:180,templet: '#status'}">状态</th>
                <th lay-data="{field:'add_time',width:180,templet: '#created_ts'}">创建时间</th>
                <th lay-data="{field:'update_time',width:180,templet: '#update_time'}">修改时间</th>
                <th lay-data="{fixed: '', width:200,fixed: 'right', align:'left', toolbar: '#barDemo'}">操作</th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">
            <a title="编辑" lay-event="edit" href="#"><i class="layui-icon" style="font-size: 25px; color:#029587;line-height: 30px">&#xe642;</i></a>
        </script>
        <script type="text/html" id="status">
            {{#  if(d.status == 1){ }}
            <span style="color: #5FB878" >正常</span>
            {{#  } }}
            {{#  if(d.status == 2){ }}
            <span style="color: #FF5722" >禁用</span>
            {{#  } }}
        </script>
    </div>
    {include file='common/footer'}
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>
        layui.use(['table','form'], function(){
            var table = layui.table
                ,form = layui.form;
            var $ = layui.$, active = {
                reload: function(){
                    var user_name = $('input[name="user_name"]').val();
                    var name = $('input[name="name"]').val();
                    //执行重载
                    table.reload('testReload', {
                        where: {
                            user_name:user_name,
                            name:name
                        }
                    });
                }
            };

            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            //监听表格复选框选择
            table.on('checkbox(demo)', function(obj){
                console.log(obj)
            });
            //监听工具条
            table.on('tool(demo)', function(obj){
                var data = obj.data;
                var event=obj.event;
                switch(event){
                    case 'edit':
                        layer.open({
                            type: 2,
                            title: '编辑更新数据信息',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['100%', '100%'],
                            content: '{:url("admin/user/userInfo")}?id='+data.id,
                            end: function () {
                                table.reload('testReload');
                            },
                        });
                        break;
                    case 'delete':
                        layer.confirm('确定删除么?', function(index){
                            $.ajax({
                                url:'{:url("admin/Admin/deleteAdmin")}',
                                type:'post',
                                dataType:'json',
                                data: {'id':data.id},
                                success:function(val){
                                    if(val.code == 200){
                                        obj.del();
                                        layer.msg(val.msg);
                                    }
                                    if(val.code == 400){
                                        layer.msg(val.msg);
                                    }
                                }
                            });

                        });
                        break;
                }
            });
            var url='{:url("user/userInfo")}';
            $('.addInfo').on('click', function() {
                layer.open({
                    type: 2,
                    title: '添加内容信息',
                    shadeClose: true,
                    shade: false,
                    maxmin: true,
                    area: ['100%', '100%'],
                    content: url,
                    end: function () {
                        table.reload('testReload');
                    },
                });
            });
        });
    </script>
    </body>
    </html>